package com.desire.test;

import java.util.Arrays;

/**
 * @author desire
 */
public class _05_遍历 {
    public static void main(String[] args) {
        Integer[] arr = new Integer[]{11, 3, 5, 6, 2, 24, 28, 4};

        //for i 正序遍历
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println("\n<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>");

        // for i 倒序遍历
        for (int i = arr.length - 1; i >= 0; i--) {
            System.out.print(arr[i] + " ");
        }
        System.out.println("\n<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>");

        //for in 循环
        for (int i : arr) {
            System.out.print(i + " ");
        }
        System.out.println("\n<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>");

        //lambda 表达式 遍历
        Arrays.stream(arr).forEach(System.out::print);

        System.out.println("\n<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>");

        //升序  (a, b) -> a-b 可以不用写 默认 升序
        Arrays.sort(arr, (a, b) -> a - b);
        //降序
        Arrays.sort(arr, (a, b) -> b - a);
        for (Integer integer : arr) {
            System.out.print(integer + " ");
        }
    }
}
